package com.itheima.sh.controller;


import com.itheima.sh.pojo.PageRequest;
import com.itheima.sh.pojo.User;
import com.itheima.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    //查询
    @GetMapping("findAll")
    public List<User> findAll(){
        return this.userService.findAll();
    }
    //添加
    @PostMapping("addUser")
    public String addUser(User user){
        this.userService.addUser(user);
        return "添加成功";
    }
    //修改
    @PutMapping("updateUser")
    public String updateUser(@RequestParam("username")String username,
                             @RequestParam("id")Long id){
        this.userService.updateUser(username,id);
        return "修改成功";
    }
    //删除
    @DeleteMapping("deleteUser")
    public String deleteUser(@RequestParam("id")Long id){
        this.userService.deleteUser(id);
        return "删除成功了";
    }

    //分页
    @PostMapping("findPage")
    public Object findPage(@RequestBody PageRequest pageRequest){
        return this.userService.findPage(pageRequest);
    }
}
